//
//  ProgressImageView.swift
//  weibo1
//
//  Created by changhongliang on 2017/8/11.
//  Copyright © 2017年 richinfo. All rights reserved.
//

import UIKit

class ProgressImageView: UIImageView {
    //进度 0 ~1
    var progress:CGFloat = 0.0
    {
        didSet{
            progressView.progress = progress
        }
    }
    
    init(){
        super.init(frame: CGRect.zero)
        setupUI()
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
       super.init(coder: aDecoder)
       setupUI()
    }
    
    private func setupUI()
    {
        //1.清空进度背景
        progressView.backgroundColor = UIColor.clear
    
        //2,添加进度视图
        addSubview(progressView)
        //3.添加约束
        progressView.translatesAutoresizingMaskIntoConstraints = false
        var cons = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[progressView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["progressView": progressView])
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[progressView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["progressView": progressView])
        addConstraints(cons)
        
    }
    
    
//MARK: - 懒加载

 private lazy var progressView: ProgressView = ProgressView()
}
